//
//  FlatmapLatestViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/25.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxSwift

class FlatmapLatestViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addTapWithHandle { (tap) in
            
            let disposeBag = DisposeBag()
            
            let boy = Variable(80)
            let girl = Variable(90)
            
//            boy.asObservable().subscribe({ (eve) in
//                print("boy \(eve)")
//            }).disposed(by: disposeBag)
//            
//            girl.asObservable().subscribe({ (eve) in
//                print("girl \(eve)")
//            }).disposed(by: disposeBag)
            
            let player = Variable(boy)
            player.asObservable()
                .flatMapLatest({ (stu) -> Observable<Int> in
                    return stu.asObservable()
                })
                .subscribe({ (eve) in
                    print(eve)
                })
                .disposed(by: disposeBag)
            
            boy.value = 85
            
            player.value = girl
            boy.value = 95
            boy.value = 96
            girl.value = 100
        }
        
    }
}
